package org.lib.rabbitmqhello.try2;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 试验2的配置：Fanout交换机
 * @author ben
 * @date 2021-08-27 21:39:53 CST
 */
@Configuration
public class RabbitConfig2 {
	
	public final static String QUEUE_21 = "queue21";
	public final static String QUEUE_22 = "queue22";
	public final static String FAN_EXCHANGE_2 = "fanout2";
	
	@Bean
	public Queue queue21() {
		return new Queue(QUEUE_21);
	}
	
	@Bean
	public Queue queue22() {
		return new Queue(QUEUE_22);
	}
	
	@Bean
	public FanoutExchange fanoutExchange() {
		// 最简单的构造函数
		return new FanoutExchange(FAN_EXCHANGE_2);
	}
	
	@Bean
	public Binding binding21(Queue queue21, FanoutExchange fanoutExchange) {
		return BindingBuilder
				.bind(queue21)
				// to后面 没有 withXXX 函数，to的结果即返回 Binding对象
				.to(fanoutExchange);
	}
	
	@Bean
	public Binding binding22(Queue queue22, FanoutExchange fanoutExchange) {
		return BindingBuilder
				.bind(queue22)
				// to后面 没有 withXXX 函数，to的结果即返回 Binding对象
				.to(fanoutExchange);
	}
	
}
